home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug106 / ntoi.c < prev    next >
Text File  |  1984-06-14  |  2KB  |  70 lines

  1. /*
  2.     this function converts ascii characters to an integer.
  3.     most common number bases may be used (except offset
  4.     octal).
  5. */
  6.  
  7. ntoi(n,b)
  8. char *n;
  9. int b;
  10. {
  11.     int val,sign;
  12.     char c;
  13.  
  14.     val=0; sign=1;
  15.     while ((c = *n) == '\t' || c == ' ') ++n;
  16.     if (c == '-') {sign = -1; n++;}
  17.     while (dig(c = *n++)) {
  18.        if (b == 16 && c >= 'A' && c <= 'F') c -= 7;
  19.        val = val * b + c - '0';
  20.     }
  21.     return sign*val;
  22. }
  23. /*
  24.     otoi(n)
  25.  
  26.     this function converts an offset octal number in ASCII
  27.     to an integer. the number is in the format xxx.xxx{a} and
  28.     may be preceeded by white space.
  29. */
  30.  
  31. otoi(n)
  32. char *n;
  33. {
  34.     int val, b, i;
  35.     char c;
  36.  
  37.     val = 0; b = 16384;
  38.  
  39.     while ((c = *n) == '\t' || c == ' ') ++n;
  40.     for (i = 0; i < 7; i++) {
  41.        if ((c = *n) == '.') {++n; b = 64;}
  42.        else {c = *n++; val = val + (b * (c - '0')); b /= 8;}
  43.     }
  44.     return val;
  45. }
  46.  
  47. /*------------------------------------------------------------------*/
  48. /*                                                                  */
  49. /*  This is a library of private routines for use with BDS C prog-  */
  50. /*  grams.  The comment lines preceding each entry are intended     */
  51. /*  to give a sufficient explanation of the routine that follows.   */
  52. /*  To link any of these routines to a BDS C program, merely name   */
  53. /*  PRVLIB as a argument following the name of the main program in  */
  54. /*  the CLINK command line.                                         */
  55. /*                                                                  */
  56. /*------------------------------------------------------------------*/
  57.  
  58.  
  59. /*
  60.     Move k bytes from blk1 to blk2.  
  61.     The two blocks may overlap.
  62.     Since k must be positive, this routine is limited to
  63.     moving blocks less than 32k in length.
  64.     Added by M. Goldberg, 25-DEC-79. 
  65. */
  66. movblk(blk1, blk2, k) 
  67.     char *blk1, *blk2;
  68.     int k;
  69.     {
  70.     int m,